#include <bits/stdc++.h>
using namespace std;

class Solution {
   public:
    int minIncrements(int n, vector<int>& cost) {
        int ret = 0;
        for (int i = n - 2; i > 0; i-=2) {
            ret += abs(cost[i] - cost[i + 1]);
            cost[i / 2] += max(cost[i + 1], cost[i]);
        }

        return ret;
    }
};